package com.fs.spring.example01;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter;

import java.beans.PropertyDescriptor;

/**
 * @author shuai.fang
 * @date：2017-08-02
 * @description：
 */
public class MyInstantiationAwareBeanPostProcessor extends InstantiationAwareBeanPostProcessorAdapter {

	private static Logger logger = LoggerFactory.getLogger(MyInstantiationAwareBeanPostProcessor.class);

	@Override
	public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {
		if ("person".equals(beanName)) {
			logger.info("InstantiationAwareBeanPostProcessor#postProcessBeforeInstantiation");
		}
		return super.postProcessBeforeInstantiation(beanClass, beanName);
	}

	@Override
	public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {
		if ("person".equals(beanName)) {
			logger.info("InstantiationAwareBeanPostProcessor#postProcessAfterInstantiation");
		}
		return super.postProcessAfterInstantiation(bean, beanName);
	}

	@Override
	public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException {
		if ("person".equals(beanName)) {
			logger.info("InstantiationAwareBeanPostProcessor#postProcessPropertyValues");
		}
		return super.postProcessPropertyValues(pvs, pds, bean, beanName);
	}
}
